from invenio.bibformat_engine import BibFormatObject
from invenio.bibknowledge import get_kb_mapping


def format_element(bfo, department="", address="", url="", contact=""):
	"""
	Prints fulltext availability if not present

	@param prefix
	@param suffix
	@param department
	@param address
	@param url
	@param contact    
	"""

	fta = bfo.field('996')
	fts = bfo.fields("8564_u")
	out = ""
	if fta and not fts:
		print "yes"
		out += "<br />"
		if bfo.lang == "en":
			out += fta.get("b", fta["a"])
		else:
			out += fta["a"]
		out += "<br />"
		vals =  get_kb_mapping("contacts", bfo.field("998__a"))["value"].split("|||")
		out += "<ul style='list-style-type:none;'>\n"
		if vals[0]:
			out += "<li><strong>%s</strong> - %s</li>\n" % (department, vals[0])
		if vals[1]:
			out += "<li><strong>%s</strong> - %s</li>\n" % (address, vals[1])
		if vals[2]:
			out += "<li><strong>%s</strong> - <a href='%s' target='_blank'>%s</a></li>\n" % (url, vals[2], vals[2])
		if vals[3]:
			out += "<li><strong>%s</strong> - %s</li>\n" % (contact, vals[3])
		out += "</ul>"
	
	
	return out
	
	
def escape_values(bfo):
    """
    Called by BibFormat in order to check if output of this element
    should be escaped.
    """
    return 0
	
if __name__ == "__main__":
	print format(BibFormatObject(96321))
